package cn.tangsihai.hrm.context;

import cn.tangsihai.hrm.domain.Login;
import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

public class LoginContext {
    public static Login getLogin(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication != null){
            Object principal = authentication.getPrincipal();
            Login loginFromToken = JSON.parseObject(principal.toString(), Login.class);
            return loginFromToken;
        }
        return null;
    }
}
